package com.blog.boot.service.system;

import com.blog.boot.api.system.Permission;
import com.blog.boot.api.system.Role;
import com.blog.boot.api.system.service.SystemService;
import com.blog.boot.api.system.service.UserService;
import com.mongodb.BasicDBList;
import com.mongodb.BasicDBObject;
import com.mongodb.client.FindIterable;
import com.mongodb.client.MongoCursor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.aggregation.Aggregation;
import org.springframework.data.mongodb.core.aggregation.AggregationOperation;
import org.springframework.data.mongodb.core.aggregation.TypedAggregation;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.stereotype.Service;

import java.util.*;

/**
 * @author : cailong
 * @since : Created in 上午 9:09 2018/12/18 0018
 */
@Service
public class SystemServiceImpl implements SystemService {

    @Autowired
    private MongoTemplate mongoTemplate;
    @Autowired
    private UserService userService;
    @Override
    public List<Permission> getPerMissionByPerM(Set<Integer> per) {
        Query query = new Query(Criteria.where("_id").in(per));
        return mongoTemplate.find(query, Permission.class);
    }

    @Override
    public Role getRoleByUserId(String id) {
        return null;
    }

    @Override
    public List<Role> getRole() {
        return mongoTemplate.findAll(Role.class);
    }

    @Override
    public List<Permission> getPermission() {
        return mongoTemplate.findAll(Permission.class);
    }

    @Override
    public Set<Permission> getPermissionByRole(String role){
        Query query = new Query(Criteria.where("_id").is(role));
        Set<Permission> objects = new HashSet<>();
        objects.addAll(mongoTemplate.find(query,Permission.class));
        return objects;
    }

    @Override
    public Role getRoleByRoleid(Long id) {
        Query query = new Query(Criteria.where("_id").is(id));
        return mongoTemplate.findOne(query, Role.class);
    }
}
